#write 写入 -->直接覆盖原内容
#with open('./files/test.txt','w',encoding='utf-8') as f:
    #f.write('我是写入的内容')

#with open('./files/test.txt','w',encoding='utf-8') as f:
#    print(f.read())

#将原本内容的第二行修改为666
f = open('./files/test.txt','r',encoding='utf-8')
str1 = f.read()
str2 = str1.replace('222','666')
print(str2)
f.close()

fw = open('./files/test.txt','w',encoding='utf-8')
fw.write(str2)
#flush 确认写入
fw.flush()

fr = open('./files/test.txt','r',encoding='utf-8')
print(fr.read())
fr.close()